package com.nlp.fresh_comp;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.nlp.fresh_comp.model.Feature;
import com.nlp.fresh_comp.model.TUser;

public class TrainDataProcess {
	Map<String, List<TUser> > data = null;
//	Set<String> user;
	Map<String, List<Feature> > user = null; 
	
	public void reload(){
//		data = new HashMap<String, List<TUser> >();
//		user = new HashSet<String>();
		BufferedReader br = new BufferedReader(new InputStreamReader(
				TrainDataProcess.class.getClassLoader().getResourceAsStream(
						"fresh_comp_offline/tianchi_fresh_comp_train_user.csv")));
		try {
			String line = null;
			int lineNum = 0;
			while (br.ready()) {
				lineNum++;
				line = br.readLine().trim();
				if( lineNum == 1 || line == null || line.length() == 0 ){
					continue;
				}
				if( lineNum % 100 == 0 ){
					System.out.println(lineNum);
				}
				TUser action = new TUser(line);
				
//				user.add( action.getUser_id() );
//				List<TUser> list = data.get( action.getUser_id() );
//				if( list == null ){
//					list = new ArrayList<TUser>();
//					data.put(action.getUser_id(), list);
//				}
//				list.add(action);
			}
			br.close();
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public boolean timeValid(String line){
		if( line.contains("2014-12-17") || line.contains("2014-12-18") ){
			return false;
		}
		return true;
	}
	
	public void actionToUser(){
//		for (String string : user) {
//			System.out.println( string );
//		}
//		System.out.println( user.size() );
		
		for (Map.Entry<String, List<TUser> > entry : data.entrySet()) {
			List<TUser> actions = entry.getValue();
			if( actions == null || actions.isEmpty() ){
				continue;
			}
			System.out.println( actions.get(0).getTime() );
		}
	}
	
	public static void main(String[] args) {
		TrainDataProcess process = new TrainDataProcess();
		process.reload();
		process.actionToUser();
	}
}
